package cn.clazz

/**
  * Created by lzd on 2018/9/5.
  */
import scala.collection.mutable.ArrayBuffer
object SingletonDemo {
  def main(args: Array[String]): Unit = {
    val session = SessionFactory.getSession()
    println(session)
  }
}

class Session{}

object SessionFactory{
  //该部分相当于java中的静态块
  var counts = 5
  val sessions = new ArrayBuffer[Session]()
  while (counts > 0){
    sessions += new Session
    counts -= 1
  }
  //在object中的方法相当于java中的静态方法
  def getSession(): Session ={
    sessions.remove(0)
  }

}
